package com.bobgao.my_first_demo.controller;


import com.bobgao.my_first_demo.entity.DoHomeworkEntity;
import com.bobgao.my_first_demo.entity.HomeWorkEntity;
import com.bobgao.my_first_demo.entity.UserEntity;
import com.bobgao.my_first_demo.req.*;
import com.bobgao.my_first_demo.resp.CommonResp;
import com.bobgao.my_first_demo.resp.PageResp;
import com.bobgao.my_first_demo.service.HomeWorkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/homework")
public class HomeworkController {

    @Resource
    private HomeWorkService homeWorkService;


    @GetMapping("/getHomeworkList")
    public CommonResp getHomeworkList(HomeWorkReq homeWorkReq){
        CommonResp<PageResp<HomeWorkEntity>> resp = new CommonResp<>();
        PageResp<HomeWorkEntity> list = homeWorkService.getHomeworkList(homeWorkReq);
        resp.setContent(list);
        return resp;
    }

    @GetMapping("/getDoHomeWorkList")
    public CommonResp getDoHomeWorkList(DoHomeWorkReq doHomeWorkReq){
        CommonResp<PageResp<DoHomeworkEntity>> resp = new CommonResp<>();
        PageResp<DoHomeworkEntity> list = homeWorkService.getDoHomeWorkList(doHomeWorkReq);
        resp.setContent(list);
        return resp;
    }

    @DeleteMapping("/deleteHomework")
    public CommonResp deleteHomework(String id){
        CommonResp<UserEntity> resp = new CommonResp<>();
        homeWorkService.deleteHomework(Long.parseLong(id));
        return resp;
    }

    @PostMapping("/saveHomework")
    public CommonResp saveHomework(@RequestBody HomeWorkSaveReq req){
        CommonResp<HomeWorkEntity> resp = new CommonResp<>();
        homeWorkService.saveHomework(req);
        return resp;
    }

    @PostMapping("/doHomeWork")
    public CommonResp DoHomeWork(@RequestBody DoHomeWorkSaveReq req){
        System.out.println(req);
        CommonResp<DoHomeworkEntity> resp = new CommonResp<>();
        homeWorkService.DoHomeWork(req);
        return resp;
    }
}
